﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PolePosition.v3.Desktop.Selectors.Controls
{
    public partial class Utilities : DialogEditBase
    {
        public Utilities()
        {
            InitializeComponent();
            BindLists();
        }

        private bool m_BindComplete = false;
        private List<EntityLibrary.UtilityEntity> m_AfterBindingCompleteSelectedUtilities = null;

        //private bool m_AllowMultiSelect = false;
        //[DefaultValue(false)]
        //public bool AllowMultiSelect 
        //{ 
        //    get
        //    {
        //        return m_AllowMultiSelect;   
        //    }
        //    set
        //    {
        //        m_AllowMultiSelect = value;
        //        if (m_AllowMultiSelect)
        //            base.Subtitle = "Select One or More Utilities";
        //        else
        //            base.Subtitle = "Select Project";

        //        listSelectorUtilities.AllowMultiSelect = m_AllowMultiSelect;

        //        //listViewExUtilities.MultiSelect = m_AllowMultiSelect;
        //    }
        //}

        //[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        //public string SelectedProjectList
        //{
        //    get { return listSelectorUtility.GetSelectedValueList<int>(); }
        //    set 
        //    { 
        //        listSelectorUtility.SetSelectedValueList<int>(value);
        //    }
        //}

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public List<EntityLibrary.UtilityEntity> SelectedUtilities
        {
            get
            {
                return listSelectorUtility.GetSelectedItems<EntityLibrary.UtilityEntity>();
            }
            set
            {
                if (!m_BindComplete)
                {
                    m_AfterBindingCompleteSelectedUtilities = value;
                    return;
                }
                
                if (value != null)
                    listSelectorUtility.SetSelectedItems<EntityLibrary.UtilityEntity>(value);
                
            }
        }

        private void BindLists()
        {
            //Load the project List
            if (Program.LoginResult != null)
            {
                listSelectorUtility.DisplayMember = EntityLibrary.UtilityEnumerations.Columns.Name.ToString();
                listSelectorUtility.ValueMember = EntityLibrary.UtilityEnumerations.Columns.UtilityId.ToString();
                listSelectorUtility.DataSource = Program.LoginResult.Utilities;
                listSelectorUtility.SelectNone();
            
                m_BindComplete = true;

                //if selected Utilities were set prior to the binding of the list then do so now 
                if (m_AfterBindingCompleteSelectedUtilities != null)
                    SelectedUtilities = m_AfterBindingCompleteSelectedUtilities;
            }
        }
    }
}
